// app/model/user.js
module.exports = (app) => {
	const {
		STRING,
		INTEGER,
		BIGINT,
		DATE,
		DECIMAL
	} = app.Sequelize;
	
	function filterDate(t){
		if(t){
			var date = new Date(t).toLocaleString();
			date = date.replace(/\//g,"-")
			return date;
		}
		return '';
	}
	
	const Coupon = app.model.define("coupon", {
		id: {
			type: INTEGER,
			primaryKey: true,
			autoIncrement: true
		},
		name: STRING,
		desc: STRING,
		tag: STRING,
		total: INTEGER,
		discount: DECIMAL,
		min: DECIMAL,
		limit: INTEGER,
		type: INTEGER,
		status: INTEGER,
		goodsType: INTEGER,
		goodsValue: STRING,
		code: STRING,
		timeType: INTEGER,
		days: INTEGER,
		startTime: {
			type: DATE,
			get() {
				const date = this.getDataValue('startTime');
				return filterDate(date);
			}
		},
		endTime: {
			type: DATE,
			get() {
				const date = this.getDataValue('endTime');
				return filterDate(date);
			}
		},
		addTime: {
			type: DATE,
			get() {
				const date = this.getDataValue('addTime');
				return filterDate(date);
			}
		},
		updateTime: {
			type: DATE,
			get() {
				const date = this.getDataValue('updateTime');
				return filterDate(date);
			}
		}
	}, {
		tableName: "dts_coupon",
		paranoid: false,
		timestamps: false,
		freezeTableName: true
	});

	return Coupon;
};